<template>
  <div class="list" ref="scroll">
    <div>
      <div class="list-title border-topbottom">您为位置</div>
      <div class="list-desc">
        <div class="list-but-wrapper">
         <div class="list-but">北京</div>
        </div>
      </div>
      <div class="list-title border-topbottom">热门城市</div>
      <div class="list-desc" >
        <div class="list-but-wrapper" v-for="item in hotCities" :key="item.id">
          <div class="list-but">{{item.name}}</div>
        </div>
      </div>
      <div v-for="(itemlist , key) of cities" :key="key" :ref="key">
        <div class="list-title">{{key}}</div>
        <div class="item-desc">
          <div class="list-A border-bottom" v-for="item in itemlist" :key="item.id">{{item.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'CityList',
  props: {
    hotCities: Array,
    cities: Object,
    letter: String
  },
  data () {
    return {
    }
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.scroll)
  },
  watch: {
    letter () {
      if (this.letter) {
        const element = this.$refs[this.letter][0]
        this.scroll.scrollToElement(element)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~style/varibles.styl"
.list
  overflow hidden
  position absolute
  top 1.65rem
  bottom 0
  left 0
  right 0
  .list-title
    background #eee
    height .5rem
    line-height .5rem
    text-indent .2rem
  .list-desc
    padding .1rem .6rem .1rem .1rem
    overflow hidden
    .list-but-wrapper
      float left
      width 33.33%
      .list-but
       border .02rem solid $bgColor
       background white
       border-radius .1rem
       margin .1rem
       padding .1rem 0
       text-align center
  .item-desc
   .list-A
     padding .2rem .2rem

</style>
